package com.cyw.common.config.jackson.serializer;

import com.cyw.common.utils.DateUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * LocalDateTime序列化
 * @author cyw
 * @date 2021-03-31
 */
public class LocalDateTime2TimestampSerializer extends StdSerializer<LocalDateTime> {

   private static final long serialVersionUID = 3073078887192126259L;

   public LocalDateTime2TimestampSerializer() {
      this(null);
   }

   public LocalDateTime2TimestampSerializer(Class<LocalDateTime> t) {
      super(t);
   }

   @Override
   public void serialize(LocalDateTime localDateTime, JsonGenerator gen, SerializerProvider provider) throws IOException {
      gen.writeNumber(DateUtils.localDateTime2timestamp(localDateTime));
   }

}